package main

import (
	"log"
	"net/http"
	"saleforce/sf-backend-gateway/config"
	"saleforce/sf-backend-gateway/constant"
	"saleforce/sf-backend-gateway/i18n"
	"saleforce/sf-backend-gateway/nacos"
	"saleforce/sf-backend-gateway/router"
	"saleforce/sf-backend-gateway/server"
	"saleforce/sf-backend-gateway/validate"
	"strconv"
	"time"
)

func main() {
	config.LoadConfig()
	log.Printf("Loaded Nacos config: %+v\n", config.NacosConf)
	client := nacos.NewNamingClient()
	err := nacos.RegisterWithRetry(client, nacos.NewRegisterParam(), 10, 2*time.Second)
	if err != nil {
		log.Fatal("❌ 注册失败：", err)
	}
	validate.InitValidator()
	router.Router()
	if constant.Engine == nil {
		log.Fatal("❌ Gin Engine 未初始化")
	}
	_ = i18n.LoadLangFile("resource/lang.json")
	http.ListenAndServe(":"+strconv.FormatUint(config.ServerConf.Port, 10), constant.Engine)
	server.StartGRPCServer(&config.ServerConf)
}
